#include <stdio.h>
#define N 5
void max_min(int array[],int n)
{

	int min,x,max,y,i,temp;	
	min = max = array[0];
	x = y = 0;
	for(i=0;i<n;i++)
	{
		if(min>array[i])
		{
			min=array[i];
			x=i; 
		}
		if(max<array[i])
		{
			max=array[i];
			y=i; 
		} 
	}

	if(x == 0 && y == n-1){
	temp = array[x];
	array[x] = array[n-1];
	array[n-1] = temp;
	}else{

	temp = array[x];
	array[x] = array[n-1];
	array[n-1] = temp;
	
	temp = array[y];
	array[y] = array[0];
	array[0] = temp;
	}
	
	for(i=0;i<n;i++) printf("%3d",array[i]);
}
int main()
{
	int i,array[N];
	for(i=0;i<N;i++) scanf("%d",&array[i]);
	max_min(array,N);
	return 0;
} 
